/**
 * Created by ACER on 2017/4/4.
 */
app.controller('email-register', function ($scope, $http) {
    //用户电话号码
    $scope.email = '';
    //用户登录密码
    $scope.password = '';
    $scope.verificationCode='';
    $scope.emailRegister = function(){

        var registerInfo = {'email':$scope.email,'password':$scope.password,'verificationCode':$scope.verificationCode};
        $http({
            method:'post',
            url:app.netPath+'/users/register/email',
            params:registerInfo
        }).then(function(res){
            console.log('hello');
            if(!res.data.error){
                $.alert('注册成功',function(){
                    location.href='#login'
                })
            }else{
                var errorCode=res.data.error;
                switch (errorCode){
                    case  101:
                        $.alert(' 注册信息不完整') ;
                        return ;
                    case 102:
                        $.alert(' 该用户已被注册');
                        return ;
                    case 200:
                        $.alert('注册失败，请重试');
                        return ;
                    default:
                        $.alert('验证码错误');
                        return;
                }
            }
        },function(res){
            console.log(res);
            $.alert('网络有问题哟');
        })
    };
    $scope.getVerificationCode=function(){
        var email={'email':$scope.email};
        $http({
            method:'get',
            url:app.netPath+'/users/getVerificationCode',
            params:email
        }).then(function(res){
            if(!res.data.error){
                $.alert('验证码发送成功');
            }else{
                $.alert("error:"+res.data.error+","+res.data.msg)
            }
        },function(res){
            console.log(res);
            $.alert('网络有问题哟');
        })
    }

});